home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
treedir.c
< prev
next >
Wrap
Text File
|
1985-06-03
|
5KB
|
237 lines
/*
TREEDIR -- Tree directory for MSDOS V2.xx.
usage: TREEDIR [directory]
If the directory is omitted, the tree starts with the root
directory. Use TREEDIR . to start from the current directory.
This program combines TREE and DIR to produce a directory
of all files in each directory along with date, time and
file size.
Totals are given for each directory, which includes the
totals of any subdirectories.
This program was primarily written to display the actual
space used on the hard disk for each directory, and the
amount of space needed to copy to a diskette.
This is due to the allocation cluster of MSDOS: files on
diskette are allocated in increments of 1024 bytes while
files on the hard disk (10 MB) are in 4096 byte chunks.
The program as written requires Lattice c, version 2.1 or
higher. No attempt was made to keep it portable, since
the dos interface is non-portable by definition. The Lattice
conio.h is used instead of stdio.h, resulting in direct console
i/o and a smaller com file.
The program also requires DOS 2.0 or higher, since it doesn't
make any sense otherwise.
Future versions will probably include sorts and hidden files
and options like SD.
Alan Losoff
Milwaukee, Wisconsin
revisions:
07-05-84 test for ^C hit (needed when bypassing standard i/o)
*/
#include <conio.h> /* Lattice direct console I/O */
#include <stamp.h> /* time/date file from my cc.bat */
/* static char *__stamp[] = {"dd/dd/dd", "tt/tt/tt"}; */
/* BDOS CALLS */
#define GETFAT 0x3600
#define SETDTA 0x1A00
#define FFIRST 0x4E00
#define FNEXT 0x4F00
#define SUBDIR 0x0010 /* attribute for sub directory */
#define CTRL_C 3
struct XREG /* for lattice bdos call */
{
short ax,bx,cx,dx,si,di;
};
struct DIRS /* dos directory entry */
{
char for_dos[21];
char attr;
struct
{
unsigned hour : 5;
unsigned minute : 6;
unsigned twosec : 5;
} time;
struct
{
unsigned year : 7;
unsigned month : 4;
unsigned day : 5;
} date;
long size;
char name[13];
char fill[85];
};
struct counts
{
int files;
int blocks;
int kbytes;
long bytes;
};
int _stack = 10000; /* set stack size (lattice specific) */
static int blocksize = 0; /* cluster size for drive specified */
main(argc, argv)
int argc;
char *argv[];
{
char *path;
path = argc > 1 ? argv[1] : "";
blocksize = cluster(path);
printf("\nTREEDIR Tree Directory version 1.01%s\n\n", __stamp[0]);
printf( "File Date Time Size Actual Kbytes\n");
pdir (path, 0);
exit();
}
pdir (path, cp) /* print & total for given path */
char *path;
struct counts *cp;
{
static margin = -2;
char *indent();
char newpath[129];
struct DIRS buf;
struct counts c;
int r, n, k;
margin += 2;
c.bytes = c.files = c.blocks = c.kbytes = 0;
for (r = first(path, &buf); !r; r = next(path, &buf))
{
kbhit(); /* checks for ^C */
if (*buf.name == '.')
continue;
printf("%-36s", indent(margin, buf.name));
if (buf.attr & SUBDIR)
{
printf("\n");
sprintf(newpath, "%s\\%s", path, buf.name);
pdir(newpath, &c);
}
else
{
n = ((buf.size + blocksize - 1) / blocksize)
* (blocksize / 1024);
k = (buf.size + 1023) / 1024;
printf("%2d/%02d/%02d %2d:%02d %9ld %5dK %5dk\n",
buf.date.month, buf.date.day, buf.date.year+80,
buf.time.hour, buf.time.minute,
buf.size, n, k);
c.files++;
c.blocks += n;
c.kbytes += k;
c.bytes += buf.size;
}
}
margin -= 2;
printf("%41s %4d files %9ld %5dK %5dk **\n\n",
"", c.files, c.bytes, c.blocks, c.kbytes);
if (cp)
{
cp->blocks += c.blocks;
cp->kbytes += c.kbytes;
cp->files += c.files;
cp->bytes += c.bytes;
}
return;
}
char *
indent (margin, name) /* indent name to margin */
int margin;
char *name;
{
int n;
static char work[129];
for (n = 0; n< margin; n++)
work[n] = ' ';
strcpy(work + margin, name);
return (work);
}
cluster(dir) /* return cluster size of disk */
char *dir;
{
struct XREG inregs, outregs;
inregs.dx = dir[1] == ':' ? dir[0] & 0x1F : 0;
inregs.ax = GETFAT;
intdos(&inregs, &outregs);
return (outregs.ax * outregs.cx);
}
first (dir, buf) /* find first directory entry */
char *dir, *buf;
{
struct XREG inregs, outregs;
char arg[129];
inregs.ax = SETDTA;
inregs.dx = (int) buf;
intdos(&inregs, &outregs);
sprintf(arg, "%s\\????????.???", dir);
inregs.ax = FFIRST;
inregs.cx = SUBDIR;
inregs.dx = (int) (&arg);
intdos(&inregs, &outregs);
return (outregs.ax);
}
next (dir, buf) /* find next directory entry */
char *dir, *buf;
{
struct XREG inregs, outregs;
char arg[129];
inregs.ax = SETDTA;
inregs.dx = (int) buf;
intdos(&inregs, &outregs);
sprintf(arg, "%s\\*.*", dir);
inregs.ax = FNEXT;
inregs.cx = SUBDIR;
inregs.dx = (int) (&arg);
intdos(&inregs, &outregs);
return (outregs.ax);
}
);
}